<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let chain = [
            () => { console.log(1);return 1; },
            () => { console.log(2);return 2; },
            () => { console.log(3);return 3; },
            () => { console.log(4);return 4; },
            () => { console.log(5);return 5; },
            () => { console.log(6);return 6; }
        ]

        // let res = chain.shift();
        // chain.shift();
        // console.log(res);
        // console.log(chain);
        let promise = Promise.resolve('ok');
        while(chain.length){
            promise = promise.then(chain.shift(),chain.shift());
            console.log(chain);
            debugger;
        }

    </script>
</body>

</html>